//
//  PywAccountListCollectionViewCell.m
//  PywSdk
//
//  Created by Jade on 16/4/15.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "PywAccountListCollectionViewCell.h"
#import "PywMasonry.h"

@interface PywAccountListCollectionViewCell()
@property (nonatomic,strong) UILabel *showLabel;
@end

@implementation PywAccountListCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

- (void)setUp
{
    [self.contentView addSubview:self.showLabel];
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    [self.showLabel mas_makeConstraints:^(PywMASConstraintMaker *make) {
        make.top.left.right.bottom.offset(0);
    }];
}

#pragma mark - getter & setter
- (UILabel *)showLabel
{
    if (!_showLabel) {
        _showLabel = [UILabel new];
        _showLabel.textAlignment = NSTextAlignmentCenter;
        _showLabel.font = [UIFont systemFontOfSize:14];
        _showLabel.backgroundColor = [UIColor whiteColor];
        _showLabel.layer.borderWidth = 0.5;
        _showLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _showLabel.layer.cornerRadius = 5;
        _showLabel.layer.masksToBounds = YES;
        _showLabel.numberOfLines = 0;
    }
    return _showLabel;
}
- (void)setSelected:(BOOL)selected{
    [super setSelected:selected];
    
    // 添加“选中是Item"时的显示效果
    if (selected) {
        _showLabel.layer.borderWidth = 1;
        _showLabel.layer.borderColor = UIColorFromRGB(0xFFBC00).CGColor;
    } else {
        _showLabel.layer.borderWidth = 0.5;
        _showLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
    }
}

#pragma mark - action Medthod
- (void)reloadCellData:(NSString *)account
{
    self.showLabel.text = account;
    [self setAccessibilityIdentifier:@"manage_addaccount"];
}

- (void)cellWithData:(NSString *)infoText andSubTitle:(NSString *)subTitle accessibilityId:(NSString *)accessibilityId{
    if (subTitle) {
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@",infoText, subTitle]];
        [attStr addAttributes:@{
                                NSForegroundColorAttributeName: RGB(252, 177, 14, 1),
                                NSFontAttributeName: [UIFont systemFontOfSize:12]
                                }range:NSMakeRange(infoText.length + 1, subTitle.length)];
        self.showLabel.attributedText = attStr;
    }else{
        self.showLabel.text = infoText;
    }
    [self setAccessibilityIdentifier:accessibilityId];
}

@end
